<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html>
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script type="text/javascript">
            //设置光标位置函数
            function setCaretPosition(ele, pos){
                if(ele.setSelectionRange){
                    //FireFox、Chrome
                    ele.focus();
                    ele.setSelectionRange(pos,pos);
                } else if (ele.createTextRange) {
                    //MS IE
                    var range = ele.createTextRange();
                    range.moveStart('character', pos);
                    range.collapse(true);
                    range.select();
                }
            }
        </script>
    </head>
    <body>
        <textarea cols="40" row="40" id="ta1">abcdefg</textarea>
        <script type="text/javascript">
            var ta = document.getElementById("ta1");
            setCaretPosition(ta,2);
        </script>
    </body>
</html>
